<div class="fsh-pop">
    <input type="password" style="display: none"/>
    <div id="add_form" class="layui-form">
        <input type="hidden" name="id" value="<%=id%>">
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>父级作业</label>
            <div class="layui-input-block">
                <input type="hidden" name="parent_id" id="parent_id" value="0" value="<%=parent_id%>">
                <input type="text" lay-verify="required" placeholder="不填默认为0代表父级" class="layui-input" id="parentTitle"
                       readonly value="<%=parentTitle%>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>序号</label>
            <div class="layui-input-block">
                <input type="text" name="numbers" lay-verify="required" placeholder="不填默认为0代表父级" class="layui-input"  value="<%=parent_id%>">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" placeholder="请输入内容" class="layui-input" value="<%=parent_id%>">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">附件</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="upload_header">上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1">
                        <input name="resource_url" type="hidden" id="resUrl">
                    </div>
                </div>
            </div>

        </div>
    </div>

</div>
<script type="text/javascript">

    layui.use(['upload', 'form'], function () {
        var upload = layui.upload;
        var form = layui.form;

        $("#parentTitle").click(function () {
            showDialog({
                title: '选择父级菜单'
                , template: 'menu'
                , width: 400
                , height: 600
                , yes: function (index, layero) {
                    var res = callbackdata();
                    layer.close(index);
                    $("#parentTitle").val(res.title);
                    $("#parent_id").val(res.key);
                }

            });

        });
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_header'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#demo1').attr('src', res.link);
                    $('#resUrl').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });

</script>
